package com.springboot.controller;

import com.springboot.dto.Doctor2;
import com.springboot.dto.OrderDoctorList;
import com.springboot.model.UserLoginForm;
import com.springboot.service.PatientMyOrderService;
import com.springboot.service.PatientRepeatOrderService;
import com.springboot.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;

/**
 * 本控制台用于响应患者复诊预约

 */
@Controller
public class PatientRepeatOrderController {
    @Autowired
    PatientRepeatOrderService patientRepeatOrderService;

    @Autowired
    UserLoginService userLoginService;

    @Autowired
    PatientMyOrderService patientMyOrderService;

    /**
     * 患者点击复诊预约时
     * @param tel
     * @return
     * @date 2020-12-21
     */
    @CrossOrigin
    @RequestMapping(value = "/patientrepeatorder")
    @ResponseBody
    public ArrayList<Doctor2> patientRepeatOrder(@RequestParam("unitphone") String tel)  {
        UserLoginForm userLoginForm = userLoginService.findUserByTel(tel);
        return patientRepeatOrderService.findOrderedDoctorsByPatientId(userLoginForm.getUserId());
    }

    /**
     * 点击医生头像，出现患者已就诊过该医生的记录
     */
    @CrossOrigin
    @RequestMapping(value = "/patientmedicalrecordbydoctor")
    public @ResponseBody
    ArrayList<OrderDoctorList> patientMedicalRecordByDoctor(@RequestParam("unitphone") String phone,
                                                            @RequestParam("doctorId") Integer doctorId) {
        UserLoginForm userLoginForm = userLoginService.findUserByTel(phone);
        Integer userId = userLoginForm.getUserId();
        ArrayList<OrderDoctorList> orderDoctorLists = patientMyOrderService.showOrderDoctors(userId);
        ArrayList<OrderDoctorList> orderDoctorLists1 = new ArrayList<>();
        //查找该患者所有就诊记录后，再筛选doctorId相同的
        for(int i =0;i<orderDoctorLists.size();i++)
        {
            OrderDoctorList orderDoctorList = orderDoctorLists.get(i);
            Integer doctorIdTemp = orderDoctorList.getOrderForm().getDoctorId();
            System.out.println("。。。。。。。。。。"+doctorId);
            System.out.println("。。。。。。。。。。"+doctorIdTemp);
            if(doctorIdTemp.equals(doctorId))
            {
                System.out.println("同个医生");
                orderDoctorLists1.add(orderDoctorList);
            }
        }
        System.out.println("患者查看该医生的就诊情况");
        return orderDoctorLists1;
    }
}
